package edu.iu.criminfo.voronoi.init;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import edu.iu.criminfo.voronoi.cases.Case;
import edu.iu.criminfo.voronoi.object.Point;

public class ParseDataFile {

	public static List<Case> parse(String filePath) {
		List<Case> caseList = new ArrayList<Case>();
		try {
			File file = new File(filePath);
			BufferedReader bufferedReader = new BufferedReader(new FileReader(
					file));
			bufferedReader.readLine();
			while (bufferedReader.ready()) {
				String line = bufferedReader.readLine();
				String[] parsed = line.split("\t");

				if (parsed[parsed.length - 3].equals("U")) { //-1
					continue;
				} else {
					double coordinateX = Double
							.parseDouble(parsed[parsed.length - 2]); //-4
					double coordinateY = Double
							.parseDouble(parsed[parsed.length - 1]); //-3
					
					if ((coordinateX == 0)||(coordinateY ==0)) {
						continue;
					}
					else {
						caseList.add(new Case(new Point(coordinateX, coordinateY)));
					}
				}

			}
			bufferedReader.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return caseList;
	}

	public static void main(String[] args) {
		List<Case> caseList = parse("data/vehicle_access.txt");
		for (Iterator<Case> it = caseList.iterator(); it.hasNext();) {
			Case aCase = it.next();
			System.out.println(aCase.getLocation().coordinateX + "\t"
					+ aCase.getLocation().coordinateY);
		}
	}
}
